home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1994 June / PC Plus Super CD coverdisc Issue 93 June 1994.iso / suprdisk / button / frmsave.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-04-02  |  7.9 KB  |  256 lines

  1. VERSION 2.00
  2. Begin Form frmSave 
  3.    BackColor       =   &H00FFFFFF&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Save to Disk"
  6.    ClientHeight    =   2835
  7.    ClientLeft      =   2805
  8.    ClientTop       =   2190
  9.    ClientWidth     =   6750
  10.    ClipControls    =   0   'False
  11.    ControlBox      =   0   'False
  12.    ForeColor       =   &H00000000&
  13.    Height          =   3240
  14.    Left            =   2745
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    MinButton       =   0   'False
  18.    ScaleHeight     =   2835
  19.    ScaleWidth      =   6750
  20.    Top             =   1845
  21.    Width           =   6870
  22.    Begin CommandButton cmdDontSave 
  23.       Caption         =   "&DON'T SAVE"
  24.       Height          =   375
  25.       Left            =   4725
  26.       TabIndex        =   4
  27.       Top             =   1980
  28.       Width           =   1740
  29.    End
  30.    Begin CommandButton cmdCancel 
  31.       Cancel          =   -1  'True
  32.       Caption         =   "Cancel"
  33.       Height          =   375
  34.       Left            =   5100
  35.       TabIndex        =   5
  36.       Top             =   1395
  37.       Width           =   1365
  38.    End
  39.    Begin CommandButton cmdSave 
  40.       Caption         =   "&SAVE"
  41.       Height          =   375
  42.       Left            =   3150
  43.       TabIndex        =   3
  44.       Top             =   1980
  45.       Width           =   1365
  46.    End
  47.    Begin TextBox tbxGroup 
  48.       Height          =   285
  49.       Left            =   3150
  50.       MaxLength       =   6
  51.       TabIndex        =   2
  52.       Top             =   1440
  53.       Width           =   1665
  54.    End
  55.    Begin DirListBox Dir1 
  56.       Height          =   1605
  57.       Left            =   300
  58.       TabIndex        =   1
  59.       Top             =   315
  60.       Width           =   2415
  61.    End
  62.    Begin DriveListBox Drive1 
  63.       Height          =   315
  64.       Left            =   300
  65.       TabIndex        =   0
  66.       Top             =   2025
  67.       Width           =   2415
  68.    End
  69.    Begin Label Label8 
  70.       BackStyle       =   0  'Transparent
  71.       Caption         =   "Directory :-"
  72.       ForeColor       =   &H00000000&
  73.       Height          =   240
  74.       Left            =   3150
  75.       TabIndex        =   6
  76.       Top             =   315
  77.       Width           =   1290
  78.    End
  79.    Begin Label lblDirectory 
  80.       BackStyle       =   0  'Transparent
  81.       Caption         =   "lblDirectory"
  82.       ForeColor       =   &H000000C0&
  83.       Height          =   240
  84.       Left            =   3150
  85.       TabIndex        =   7
  86.       Top             =   630
  87.       Width           =   3465
  88.    End
  89.    Begin Label Label7 
  90.       BackStyle       =   0  'Transparent
  91.       Caption         =   "Group Name (Max. 6 characters)"
  92.       ForeColor       =   &H00000000&
  93.       Height          =   285
  94.       Left            =   3150
  95.       TabIndex        =   8
  96.       Top             =   1035
  97.       Width           =   2865
  98.    End
  99. Option Explicit
  100. Dim FileEnd(0 To 4) As String
  101. Sub cmdCancel_Click ()
  102.     frmSave.Tag = CANCEL_SAVE
  103.     frmSave.Hide
  104. End Sub
  105. Sub cmdDontSave_Click ()
  106.     frmSave.Tag = NOT_SAVED
  107.     frmSave.Hide
  108. End Sub
  109. Sub cmdSave_Click ()
  110.     Dim n As Integer
  111.     Dim Msg As String
  112.     Dim Directory As String
  113.     Dim Answer As Integer
  114.     On Error GoTo Wrong
  115.     If tbxGroup = "" Then
  116.         Error 32760
  117.     End If
  118.     GroupName = tbxGroup
  119.     Directory = lblDirectory
  120.     If Right$(Directory, 1) <> "\" Then Directory = Directory & "\"
  121.     Select Case frmSave.Tag
  122.         'All 3 buttons will saved as individual BMP files
  123.         'so we need to update the disabled button
  124.         Case S_TYPE_INDIVIDUAL
  125.             Update_Button
  126.             For n = 0 To 2
  127.                 FileEnd(n) = Directory & GroupName & FileEnd(n)
  128.                 Answer = SaveOK(FileEnd(n))
  129.                 Select Case Answer
  130.                     Case 6           'OK to save
  131.                         SavePicture B(n).Image, FileEnd(n)
  132.                         ButtonChanged = False
  133.                     Case 7           'Cancel
  134.                         ButtonChanged = False
  135.                     Case Else        'Don't save
  136.                     ButtonChanged = True
  137.                 End Select
  138.             Next n
  139.         Case Else
  140.             FileEnd(3) = Directory & GroupName & FileEnd(3)
  141.             FileEnd(4) = Directory & GroupName & FileEnd(4)
  142.             Answer = SaveOK(FileEnd(3))
  143.             Select Case Answer
  144.                 Case 6              'OK to save
  145.                     'Save the picture
  146.                     SavePicture frmBitMap!picBitMap.Image, FileEnd(3)
  147.                     BitMap.Changed = False
  148.                     'Save the Data file
  149.                     Save_BitMap_Info
  150.                     ButtonChanged = False
  151.                 Case 7              'Cancel
  152.                     ButtonChanged = False
  153.                     BitMap.Changed = False
  154.                 Case Else
  155.                     Rem             'Don't save
  156.             End Select
  157.     End Select
  158.     Select Case Answer
  159.         Case 2
  160.             Answer = CANCEL_SAVE
  161.         Case 6
  162.             CurrentDirectory = Dir1.Path
  163.             Answer = SAVED
  164.         Case Else
  165.             Answer = NOT_SAVED
  166.     End Select
  167.     frmSave.Tag = Answer   'The calling routine reads the tag to see what happened
  168.     frmSave.Hide
  169. Exit Sub
  170. Wrong:
  171.     If Err = 32760 Then
  172.         Msg = "You haven't entered a Group name"
  173.     Else
  174.         Msg = Error$
  175.     End If
  176.     MsgBox Msg, 0, "Save Button"
  177.     Exit Sub
  178.     Resume Next
  179. End Sub
  180. Sub Dir1_Change ()
  181.     lblDirectory = Dir1.Path
  182. End Sub
  183. Sub Dir1_Click ()
  184.     lblDirectory = Dir1.Path
  185. End Sub
  186. Sub Drive1_Change ()
  187.     On Error Resume Next
  188.     Dir1.Path = Drive1.Drive
  189.     If Err Then
  190.         MsgBox Error$, 0, "Drive"
  191.         Drive1.Drive = Dir1.Path
  192.     End If
  193. End Sub
  194. Sub Form_Activate ()
  195. '   The user supplies a 6 letter group name & the following endings are added
  196.     'File endings for buttons saved individually
  197.     FileEnd(0) = "_U.BMP"     'Up
  198.     FileEnd(1) = "_D.BMP"     'Down
  199.     FileEnd(2) = "_O.BMP"     'Off - Disabled
  200.     'File endings for buttons saved in a master bitmap
  201.     FileEnd(3) = "_B.BMP"     'The BMP file
  202.     FileEnd(4) = "_B.DAT"     'The Data file
  203.     lblDirectory = Dir1.Path
  204.     tbxGroup = GroupName
  205.     tbxGroup.SetFocus
  206.     'If a file has previously been loaded then CurrentDirectory will
  207.     'contain the directory it came from
  208.     If Len(CurrentDirectory) > 0 Then Dir1.Path = CurrentDirectory
  209.     HelpItem = 23
  210. End Sub
  211. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  212.     If KeyCode = &H70 Then Cheap_Help Format$(HelpItem)
  213. End Sub
  214. Sub Form_Load ()
  215.     Position_Form frmSave
  216.     KeyPreview = True
  217. End Sub
  218. '   This routine saves all the information needed
  219. '   to reload the master bitmap
  220. Sub Save_BitMap_Info ()
  221.     Dim handle As Integer
  222.     On Error GoTo FileErr
  223.     handle = FreeFile
  224.     BitMap.ID = BUTTON_ID
  225.     Open FileEnd(4) For Random As #handle Len = Len(BitMap)
  226.         Put #handle, , BitMap
  227.     Close #handle
  228. GetOut:
  229. Exit Sub
  230. FileErr:
  231.     MsgBox "Unable to save bitmap info " & Error$
  232.     Resume GetOut
  233. End Sub
  234. Function SaveOK (F$) As Integer
  235.     Dim l As Long
  236.     On Error Resume Next
  237.     l = FileLen(F$)   'If the file doesn't exist then FileLen will
  238.                       'return err 53 (File not found). This means
  239.                       'we can safely save the file
  240.                       'If a file of the same name exists then err=0
  241.                       'so we can check if it's OK to replace it
  242.                       'Any other err number means something has gone wrong
  243.     Select Case Err
  244.         Case 0
  245.             SaveOK = MsgBox("Overwrite existing file?", 35, F$)
  246.         Case 53
  247.             SaveOK = 6
  248.         Case Else
  249.             MsgBox Error$
  250.     End Select
  251. End Function
  252. Sub tbxGroup_GotFocus ()
  253.     tbxGroup.SelStart = 0
  254.     tbxGroup.SelLength = Len(tbxGroup)
  255. End Sub
  256.